package model.searchers.advancedSearchers.hashTableSearchers;

import java.io.BufferedReader;
import java.io.IOException;

import model.searchers.advancedSearchers.AdvancedGenericSearcher;

import model.searchers.advancedSearchers.hashTableSearchers.StaticHashTable;
import model.searchers.URLList;

/**
 * Class GenericHashTableSearcher represents a searcher, which can make look ups in a hash table
 * created from a file. It searches for the URLs on which a given search word occurs, and the number of occurrences on each URL. 
 * It is furthermore possible to put new data in the hash table.
 */
public abstract class GenericHashTableSearcher extends AdvancedGenericSearcher {

	protected StaticHashTable data = new StaticHashTable(100);

	/**
	 * Constructor of GenericHashTableSearcher calls constructor of superclass AdvancedGenericSearcher
	 */
	public GenericHashTableSearcher() {
		super();
	}

	/**
	 * Put search word and corresponding URL into the data hash table
	 */
	@Override
	public void put(String key, String value) {
		//because of nature of hash tables, put-functionality is in the class of the data structure, so call is passed to it
		data.put(key, value);
	}

	@Override
	public void put(String key) {
		//put-method with only one parameter is not supported as hash tables inputs a pair of key and value
		throw new UnsupportedOperationException(
				"Not supported, use put(String key, String value)");
	}

	/**
	 * Retrieve the URLList of URLs on which the specified search word occurs from the data hash table
	 * 
	 * @param key search word
	 */
	@Override
	public URLList get(String key) {
		//because of nature of hash tables, search functionality is in the class of the data structure, so call is passed to it
		return data.get(key);
	}

	/**
	 * Create a sample of specified size containing (pseudo)random search words from the hash table.
	 * To be used for benchmarking
	 * 
	 * @param sampleSize	size of sample
	 * @return	array of search words
	 */
	@Override
	public String[] createSample(int sampleSize) {
		return data.createSample(sampleSize);
	}
	
	/**
	 * Increment total number of words in hash table
	 */
	@Override
	public void incrementTotalWordCount() {
		data.incrementTotalWordCount();
	}

	@Override
	public int getTotalWordCount() {
		return data.getTotalWordCount();
	}
	
	@Override
	public String toString() {
		String result = super.toString() + "\r\nHashtable Array length: " + data.getLength();
		return result;
		
	}

}